package cn.driver.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.driver.domain.Car;
import cn.driver.domain.Student;
import cn.driver.service.CarService;
import cn.driver.utils.MyException;

@RestController
@RequestMapping("/car")
public class CarController {
	@Autowired
	private CarService carService;
	//添加车俩
		@RequestMapping("/regist")
		public Map<Object,Object> regist(String car_id,String teacher,String remarks){
			Map<Object,Object> map = new HashMap<Object,Object>();
			try{
				
					carService.regist( car_id,teacher, remarks);
					map.put("success", true);
				
			}catch (MyException e) {
				e.printStackTrace();
				map.put("success", false);
				map.put("message", e.getMessage());
			}catch(Exception e){
				e.printStackTrace();
			}
			return map;
		}
		//遍历车辆信息
		@RequestMapping("/list")
		public List<Car> carInfo(){
			return carService.carInfo();
		}
		
		//遍历车辆信息
		@RequestMapping("/search")
		public List<Car> carSearch(String info){
			return carService.carSearch(info);
		}
		//删除学员
		@RequestMapping("/delete")
		public Map<Object,Object> deleteCar(String car_id){
			Map<Object,Object> map = new HashMap<Object,Object>();
			try{
				
				carService.deleteCar(car_id);
					map.put("success", true);
				
			}catch (MyException e) {
				e.printStackTrace();
				map.put("success", false);
				map.put("message", e.getMessage());
			}catch(Exception e){
				e.printStackTrace();
				map.put("success", false);
				map.put("message", e.getMessage());
			}
			return map;
		}
		//查找单个学员信息
		@RequestMapping("/selectInfo")
		public Car selectInfo(String car_id){
			return carService.selectCar(car_id);
		}
			//修改学员信息
			@RequestMapping("/update")
			public Map<Object,Object> updateCar(
					String car_id,String teacher,String remarks,String info){
				Map<Object,Object> map = new HashMap<Object,Object>();
				try{
					
					carService.updateCar(car_id,teacher, remarks,info);
						map.put("success", true);
					
				}catch(Exception e){
					e.printStackTrace();
					map.put("success", false);
					map.put("message", e.getMessage());
				}
				return map;
			}
}
